package com.lh.unit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @author 梁昊
 * @date 2018/10/23
 * @function
 * @editLog
 */
@Component
public class CheckAccessTokenClass {
    @Autowired
    RedisOperator redisOperator;

    /**
     * 从Redis中验证token
     *
     * @param keyName     userId
     * @param accessToken token
     * @return 是否匹配
     */
    public boolean checkUseToken(String keyName, String accessToken) {
        String nowAccessToken = redisOperator.getString(keyName);
        if (nowAccessToken != null) {
            return nowAccessToken.equals(accessToken);
        } else
            return false;
    }

    /**
     * 得到ProjectId
     *
     * @param keyName token
     * @return projectId
     */
    public String getProjectId(String keyName) {
        return redisOperator.getString(keyName);
    }
}
